package com.example.bookstore;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

public class Main {
    public static void main(String[] args) {
        BookComparator bc = new BookComparator();
        Book b1 = new Book("数学建模实用教程", "韩中庚", 42);
        Book b2 = new Book("柳州螺蛳粉", "陈奕", 68);
        Book b3 = new Book("解析Python网络爬虫", "秦绪好", 72);
        Book b4 = new Book("python数据分析与应用", "黄红梅", 49);
        ArrayList<Book> list = new ArrayList<>();
        list.add(b1);
        list.add(b2);
        list.add(b3);
        list.add(b4);

        System.out.println("按价格升序排序：");
        Collections.sort(list, bc);
        for (Book book : list) {
            System.out.println(book.getTitle() + " " + book.getAuthor() + " " + book.getPrice());
        }
        System.out.println("--------------------------");

        System.out.println("按价格降序排序：");
        Comparator<Book> bcre = Collections.reverseOrder(bc);
        Collections.sort(list, bcre);
        for (Book book : list) {
            System.out.println(book.getTitle() + " " + book.getAuthor() + " " + book.getPrice());
        }
        System.out.println("--------------------------");

        System.out.println("随机排序：");
        Collections.shuffle(list);
        for (Book book : list) {
            System.out.println(book.getTitle() + " " + book.getAuthor() + " " + book.getPrice());
        }
        System.out.println("--------------------------");

        System.out.println("最贵的书是：" + Collections.max(list, bc).getTitle());
    }
}